<?php
    $this->headTitle($this->translator('product_search_page_title'));

    $this->headLink()
        ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.core.css')
        ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.resizable.css')
        ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.dialog.css')
        ->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.theme.css')
        ;

    $this->headScript()
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.core.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.draggable.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.droppable.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.resizable.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.dialog.js')
        ;
?>
<style>
    .col_50l{
        float:left;
        width:48%;
    }
    .col_50r{
        float:right;
        width:48%;
    }
    .subrow{
        padding-bottom:10px;
        display:table;
        width:100%;
    }
    .col_70l{
        float:left;
        width:69.2%;
    }
    .col_30r{
        float:right;
        width:30%;
    }
    .col_30l{
        float:left;
        width:29%;
    }
    .col_70r{
        float:right;
        width:70%;
    }
    .webwidget_vertical_menu li{
        margin-left:0px;
    }
    .caption_box{
        margin-bottom:5px; background:#EFEDED none repeat;
    }
    .caption_box span{
        padding:8px;
        text-transform:uppercase;
    }
    .box_33l{
        float:left;
        width:33.3%;
        background:#EFEDED none repeat;
    }
    .subbox_33l{
        background:#FFFFFF;
        margin:5px 0px 10px 5px;
        padding:5px
    }
</style>
<?php
    $skin_url = $this->APP_STATIC_SERVER . '/skins/'. $this->APP_TEMPLATE . '/'. $this->APP_SKIN;
?>
<div class="grid_12 pb10">
    <!--Search form-->
    <?php echo $this->widget('shop', 'searchform', array());?>
    <!--End search form-->
</div>
<div class="grid_12">
    <div class="col_70l">
        <div class="subcolumns">
            <!--Search box-->
            <?php if($this->key):?>
                <div class="caption_box icon_title">
                    <span><?php echo $this->translator('search_result');?></span>
                </div>
                <div style="padding-bottom:5px;"><label style='color:#FF9900; font-weight:bold;'><?php echo $this->numProduct;?></label> <?php echo $this->translator('search_guide');?> "<label style='color:#FF9900; font-weight:bold;'><?php echo $this->exp['keyword'];?></label>"</div>
                <?php $i=0; foreach ($this->products as $product):?>
                <?php
                    /**
                    * Check image exist directory
                    **/
					if($product->product_image){
						$arr  = explode(',',$product->product_image);
						$file = $arr[0]; 
						$path = str_replace($this->APP_STATIC_SERVER,getcwd(),$file);
						$file = Tomato_Helper_Helper::checkFile($path, $file, '_thumbnail');
					}
                    $urlImage = $file?$file:null;

                    /**
                    * Category follow product
                    **/
                    $objCategory = $this->arrPC[$product->product_id];

                    /**
                    * Enterprise follow product
                    **/
                    $objEnterprise = $this->arrPE[$product->product_id];

                    /**
                    * Param url detail
                    **/
                    $arrRouteDetail = array(
                        'enterprise_id' => $objEnterprise->id,
                        'enterprise_name' => Tomato_Utility_String::removeSign($objEnterprise->company_name_en, '-', true),
                        'cat' => $objCategory->category_id,
                        'slug' => ($objCategory->slug)?$objCategory->slug:Tomato_Utility_String::removeSign($objCategory->category_admin_name, '-', true),
                        'product_id' => $product->product_id,
                        'pro_slug' => ($product->slug)?$product->slug:Tomato_Utility_String::removeSign($product->product_admin_name, '-', true),
                    );
						
				/**
				 * code Hung them vao 
				**/
					$coreQty = null;
					$quantity = null;
					if('non_deliver_able' == $product->product_status_of_delivery){
						$quantity = "<span style='color:red;'>".$this->translator("product_status_of_delivery_non_deliverable")."</span>";
						$coreQty = $product->product_status_of_delivery;
					}
					elseif('please_contact' == $product->product_status_of_delivery){
						$quantity = $this->translator("product_status_of_delivery_".$product->product_status_of_delivery);
						$coreQty = $product->product_status_of_delivery;
					}
					else{
						$quantity = ($product->product_quantity)?$product->product_quantity:"<span style='color:red;'>".$this->translator("product_status_of_delivery_non_deliverable")."</span>";
						$coreQty = $product->product_quantity_mode;
					}
				/**
				 * end code  
				**/
                ?>
                <?php if($i%2==0):?>
                <div class="subrow">
                <?php endif;?>
                    <div class="<?php if($i%2==0):?>col_50l<?php else:?>col_50r<?php endif;?>">
                        <div class="subcolumns_oldgecko">
                            <a href="<?php echo $this->url($arrRouteDetail,'shop_product_detail');?>"><span class="title"><?php echo ($product->product_content_name)?$product->product_content_name:$product->product_admin_name;?></span></a>
                        </div>
                        <div class="subcolumns_oldgecko" style="padding-bottom:5px;">
                            <div class="geckol" style="padding-right:5px;">
                                <?php if($urlImage):?>
                                    <a href="<?php echo $this->url($arrRouteDetail,'shop_product_detail');?>"><img class="item_img" width="95" src="<?php echo $urlImage;?>" /></a>
                                <?php else:?>
                                    <a href="<?php echo $this->url($arrRouteDetail,'shop_product_detail');?>"><img class="item_img" src="<?php echo $this->baseUrl(); ?>/skins/bizprofile/default/html/images/img.jpg" /></a>
                                <?php endif;?>
                            </div>
							<!--Hung sua:
								Muc dich:Cho an neu ko co du lieu do ve
							-->
                            <div class="geckor">
                                <div style="text-align:justify">
                                    <?php echo strip_tags(Tomato_Helper_Helper::substring($product->product_content_description, 70));?>
                                </div>
                                <div>
                                    <?php echo $this->translator('front_product_price');?>:
                                    <strong><?php echo $product->product_price;?> <?php echo $product->product_price_currency;?></strong>
                                </div>
								<?php if($product->product_shipping_price_1 > 0):?>
                                <div style="width:50%; float:left;">
                                    <i><?php echo $this->translator('front_product_shipping_price')?></i><br />
                                    <strong><?php echo $product->product_shipping_price_1;?> <?php echo $product->product_price_currency;?></strong>
                                </div>
								<?php endif;?>
								<!--
								<?php// if($product->product_quantity > 0):?>
                                <div style="width:50%; float:left;">
                                    <?php //echo $this->translator('front_product_source')?></i><br />
                                    <strong><?php //echo $product->product_quantity;?></strong> <?php //echo $this->translator('front_product_source_guide');?>
                                </div>
								<?php //endif;?>
								-->
								<!--CODE Hung THEM VAO-->
								<?php if($coreQty != 'infinity'):?>
									<div style="width:50%; float:left;">
										<?php echo $this->translator('front_product_source')?></i><br />
											<strong><?php echo $quantity;?></strong>
									</div>	
								<?php endif;?>
								<!--KET THUC THEM VAO-->
                            </div>
							
							<!--ket thuc code sua-->
							
                        </div>
                    </div>
                <?php $i++; if($i%2==0):?>
                </div>
                <?php endif;?>
                <?php endforeach;?>
                <?php if($i%2!=0):?>
                </div>
                <?php endif;?>
                <?php if($this->numProduct > 0):?>
                    <div class="b_a_paginator"><?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?></div>
                <?php endif;?>

                <!--Search related box-->
                <div class="caption_box icon_title">
                    <span><?php echo $this->translator('search_result_related');?></span>
                </div>
                <div id="outputRelated" style="display:table;width:100%;"></div>
            <?php else:?>
                <div style="text-align:center"><?php echo $this->translator('search_not_key');?></div>
            <?php endif;?>
        </div>
    </div>
    <div class="col_30r">
        <!--Most viewed box-->
        <?php echo $this->widget('shop','mostviewed',array()); ?>

        <!--Most buy box-->
        <?php echo $this->widget('shop','mostbuy',array()); ?>
    </div>
</div>
<div class="grid_12">
    <?php echo $this->widget('bizprofile','contact',array()); ?>
</div>

<script type="text/javascript">
$(document).ready(function() {
    /**Auto load ajax*/
    <?php if($this->key):?>
    ajaxLoad();
    <?php endif;?>
});

function ajaxLoad(){
    var keyword = '<?php echo isset($this->exp['keyword'])?$this->exp['keyword']:null;?>';
    var category_id = '<?php echo isset($this->exp['category_id'])?$this->exp['category_id']:'all'?>';
    var strPId = '<?php echo $this->strPId?>';

    $("#outputRelated").html('').addClass('t_a_ui_helper_loading');
    jQuery.ajaxq('product', {
        type: 'POST',
        url: "<?php echo $this->url(array(), 'shop_product_search_ajax'); ?>",
        data: { keyword:keyword, category_id:category_id, strPId:strPId },
        success: function(html) {
            $("#outputRelated").html('').removeClass('t_a_ui_helper_loading');
            $('#outputRelated').html(html);
        }
    });
}
</script>